import java.util.Scanner;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-03-04
 * Time:14:31
 * Text：四元组问题
 */
public class Text16 {
    public static String four(){
        Scanner scan = new Scanner(System.in);
        int size=scan.nextInt();
        int[] arr=new int[size];
        for(int i=0;i<size;i++){
            arr[i]=scan.nextInt();
        }
        int n = arr.length;
        int[] minLeft = new int[n+1];
        int[] maxRight = new int[n+1];

        // 从左到右找到每个元素的最大值
        minLeft[0] = 0;
        for (int i = 1; i < n; i++) {
            minLeft[i] = Math.max(minLeft[i - 1], arr[i-1]);
        }

        // 从右到左找到每个元素的最小值
        maxRight[n] = Integer.MAX_VALUE;
        for (int i = n - 1; i > 0; i--) {
            maxRight[i] = Math.min(maxRight[i + 1], arr[i]);
        }

        for (int i = 1; i < n - 2; i++) {
            if (arr[i] > minLeft[i] ) {
                for (int j = i + 1; j < n - 1 ; j++) {
                    if (arr[j] < minLeft[i] && arr[j] > maxRight[i] ) {
                        return "YES";
                    }
                }
            }
        }

        return "NO";
    }
    public static void main(String[] args) {
        System.out.print(four());
    }
}
